//
//  MKUIElementViewButton.m
//  MKUI
//
//  Created by 苏尚进 on 2023/7/10.
//  Copyright © 2023 moon. All rights reserved.
//

#import "MKUIElementViewButton.h"

@implementation MKUIElementViewButton

- (id)initWithFrame:(CGRect)frame{
    if(self=[super initWithFrame:frame]){
        self.subTitleLabel.hidden = YES;
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        self.flowLayoutConstraint = [[MKUIFlowLayoutConstraint alloc] initWithItems:@[self.iconImageViewLayoutConstraint,self.titleLabel] constraintParam:(MKUIFlowLayoutConstraintParam_H_C_C) contentInsets:UIEdgeInsetsZero interitemSpacing:self.segLayoutConstraint.interitemSpacing];
        self.segLayoutConstraint = nil;
    }
    return self;
}
- (void)layoutContentView{
    [super layoutContentView];
    CGRect bounds = self.contentView.bounds;
    self.flowLayoutConstraint.bounds = bounds;
    [self.flowLayoutConstraint layoutItemsWithResizeItems:YES];
}
- (void)setButtonStyle:(MKUIElementViewButtonStyle)buttonStyle{
    _buttonStyle = buttonStyle;
    switch (self.buttonStyle) {
        case MKUIElementViewButtonStyleDefault:
            self.titleLabel.textColor = [UIColor systemBlueColor];
            break;
        case MKUIElementViewButtonStyleDestructive:
            self.titleLabel.textColor = [UIColor systemRedColor];
            break;
        default:
            break;
    }
}
@end

@implementation MKUIElementListViewCellButton
+ (Class)elementViewClass{
    return MKUIElementViewButton.class;
}
@end

@implementation MKUIElementTableViewCellModelButton
- (MKUIElementViewButtonStyle)el_buttonStyle{
    return (MKUIElementViewButtonStyle)[self mk_integerForKeyPath:@"el_buttonStyle"];
}
- (void)setEl_buttonStyle:(MKUIElementViewButtonStyle)el_buttonStyle{
    self[@"el_buttonStyle"] = @(el_buttonStyle);
    self.el_elementView.buttonStyle = el_buttonStyle;
}
@end
@implementation MKUIElementTableViewCellButton
+ (Class)elementViewClass{
    return [MKUIElementViewButton class];
}
- (void)customReloadCellModel{
    [super customReloadCellModel];
    MKUIElementTableViewCellModelButton *cm = self.cellModel;
    MKUIElementViewButton *elementView = self.elementView;
    elementView.buttonStyle = cm.el_buttonStyle;
}
@end
